package mogowtools.client.fx;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.Element;

public class Styles 
{
	private Properties cssAttributes;
	private JavaScriptObject effect;
	private Element elem;
	private Options options;
	
	public Styles(UIObject element, Options opts, Properties prop)
	{
		this.elem = element.getElement();
		this.options = opts;
		this.cssAttributes = prop;
		this.effect = newStylesObject();
	}

	public Styles(UIObject element, Properties prop)
	{
		this.elem = element.getElement();
		this.options = new Options();
		this.cssAttributes = prop;
		this.effect = newStylesObject();
	}
	
	public JavaScriptObject getOptions()
	{
		return this.options.value();
	}
	
	public void start()
	{ 
		startAnim((JavaScriptObject)this.cssAttributes.properties());
	}
	
	public void addListener(StyleListener s)
	{
		this.options.addStyleListener(s);
	}
	
	public void stop()
	{
		stopAnim();
	}
	
	private native JavaScriptObject newStylesObject()
	/*-{
		return new $wnd.Fx.Styles(
			this.@mogowtools.client.fx.Styles::elem,
			this.@mogowtools.client.fx.Styles::getOptions()());
	}-*/;
	
	private native void startAnim(JavaScriptObject properties)
	/*-{
	 var fx = this.@mogowtools.client.fx.Styles::effect;
	 fx.start(properties);
	}-*/;
	
	private native void stopAnim()
	/*-{
	 var fx = this.@mogowtools.client.fx.Styles::effect;
	 fx.stop();
	}-*/;

	public Properties getCssAttributes() {
		return cssAttributes;
	}

	public void setCssAttributes(Properties cssAttributes) {
		this.cssAttributes = cssAttributes;
	}
}

